1 // Copyright (C) 2024 Rubén Beltrán del Río
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see https://map.tranquil.systems.
20 struct MapRenderView: View {
22 @Binding var document: MapDocument
23 @Binding var evolution: StageType
26 Stage.stages(evolution)
29 var parsedMap: ParsedMap {
30 MapParser.parse(content: document.text)
33 let mapSize = Dimensions.mapSize
34 let padding = Dimensions.mapPadding
36 let lineWidth = CGFloat(0.5)
37 let vertexSize = CGSize(width: 25.0, height: 25.0)
39 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
42 ZStack(alignment: .topLeading) {
47 x: -padding, y: -padding, width: mapSize.width + padding * 2,
48 height: mapSize.height + padding * 4))
51 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
53 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
55 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
56 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
58 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
59 onDragVertex: onDragVertex)
61 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
62 opportunities: parsedMap.opportunities)
63 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
67 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
68 }.offset(x: padding, y: padding).frame(
69 width: mapSize.width + 2 * padding,
70 height: mapSize.height + 2 * padding, alignment: .topLeading
77 document: Binding.constant(MapDocument(text: "")),
78 evolution: Binding.constant(StageType.general)